Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

TryteString.random() use cls.LEN as its default length, when available #167

Closed
wants to merge 2 commits into from

Conversation

rpitonak
Copy link
Contributor

Fix #166

Copy link
Contributor

@todofixthis todofixthis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Radoslav. Thanks for jumping on this!!

I've requested a few changes, to make the code and error message a bit more explicit.

Also, could we include unit tests for this change?

iota/types.py Outdated
@@ -60,6 +60,12 @@ def random(cls, length):
alphabet = list(itervalues(AsciiTrytesCodec.alphabet))
generator = SystemRandom()

try:
length = length or cls.LEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also trip if length == 0; could we change this to an explicit is None check?

iota/types.py Outdated
length = length or cls.LEN
except AttributeError: # class has no LEN attribute
if length is None:
raise TypeError("random() missing 1 required positional argument: 'length'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this might be confusing to some users, since the method signature shows length as optional.

Maybe we could make this error explain that {class} does not define a length property.

@todofixthis
Copy link
Contributor

Hi @rpitonak let me know if there's anything I can do to help with this!

@todofixthis
Copy link
Contributor

Thanks @rpitonak ! I will take a look at this over the weekend.

@todofixthis
Copy link
Contributor

Cheers @rpitonak ! The changes look good. Two last things:

  • There's a few conflicts that need to be resolved before we can merge. We're in the process of PEP-8-ifying the codebase, so it should just be some whitespace changes.
  • Could we also include a couple of unit tests for this change?

@lzpap
Copy link
Member

lzpap commented Jan 15, 2020

Change implemented in another PR, see #286 for details.

@lzpap lzpap closed this Jan 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants